package com.djakapm.swing.component;

import javax.swing.*;
import java.awt.*;

public class SplitPaneView extends JSplitPane {
    private double proportionalLocation = 0.5;
    private boolean isPainted = false;

    public SplitPaneView() {
    }

    public void splitHorizontally(Component leftComponent, Component rightComponent) {
        this.setOrientation(HORIZONTAL_SPLIT);
        this.setLeftComponent(leftComponent);
        this.setRightComponent(rightComponent);
    }

    public void splitVertically(Component topComponent, Component bottomComponent) {
        this.setOrientation(VERTICAL_SPLIT);
        this.setLeftComponent(topComponent);
        this.setRightComponent(bottomComponent);
    }

    public void setDividerLocation(double proportionalLocation) {
        if (!isPainted) {
            this.proportionalLocation = proportionalLocation;
        } else {
            super.setDividerLocation(proportionalLocation);
        }
    }

    public void paint(Graphics g) {
        super.paint(g);
        if (!isPainted) {
            super.setDividerLocation(proportionalLocation);
            isPainted = true;
        }
    }

}
